
/*
######################################################
# REPLICATION FILE FOR
# "Sustaining Capitalism and Democracy: Lessons from 
#     Global Competition Policy"
# By Michael O Allen and Kenneth Scheve
#
# IN THIS FILE:
#   Gravity analysis
######################################################
*/

// Load data set
cd "/Users/moda/Desktop/ISR Replication/Data"
use "gravity.dta", clear

/* CLEAN/TRANSFORM DATA */
// ln Imports for OLS
gen ln_imports = log(imports + 1)

// Trade Share Variable for MPML
gen tradeShare_expend = imports / expend_importer

// Set to missing if either country is missing CLI data
gen cli_imp_greater = 0 if cli_importer != . & cli_exporter != .
replace cli_imp_greater = 1 if cli_importer > cli_exporter & cli_importer != . & cli_exporter != .

// Label for regression output
label variable cli_imp_greater "CLI\textsubscript{imp} $>$ CLI\textsubscript{exp}" 
label variable cli_importer "CLI\textsubscript{imp}" 
label variable pta "PTA"
label variable pta_comp "PTA\textsubscript{Comp. Chap.}"
label variable wto_both "Both in WTO"
label variable comcur "Currency Union"

/* TABLE 1 - MPML ESTIMATES */
// Model 1: Bivariate
ppmlhdfe tradeShare_expend cli_imp_greater if tradeShare_expend < 1, absorb(importer_ccode#year exporter_ccode#year importer_ccode#exporter_ccode) clus(importer_ccode#exporter_ccode) nolog
est store mpml_expend_nocntrl
estadd local fe_ddyad "Yes"
estadd local fe_impyear "Yes"
estadd local fe_expyear "Yes"
estadd local years "1960-2010"

// Model 2: No PTA Chapter variable
ppmlhdfe tradeShare_expend cli_imp_greater pta wto_both comcur if tradeShare_expend < 1, absorb(importer_ccode#year exporter_ccode#year importer_ccode#exporter_ccode) clus(importer_ccode#exporter_ccode) nolog d
est store mpml_expend_cntrl
estadd local fe_ddyad "Yes"
estadd local fe_impyear "Yes"
estadd local fe_expyear "Yes"
estadd local years "1960-2010"

predict yhat, xb
gen z2 = yhat^2
drop yhat


// Model 3: Full controls
ppmlhdfe tradeShare_expend cli_imp_greater pta pta_comp wto_both comcur if tradeShare_expend < 1, absorb(importer_ccode#year exporter_ccode#year importer_ccode#exporter_ccode) clus(importer_ccode#exporter_ccode) nolog d
est store mpml_expend_full_cntrl
estadd local fe_ddyad "Yes"
estadd local fe_impyear "Yes"
estadd local fe_expyear "Yes"
estadd local years "1960-2010"

predict yhat, xb
gen z3 = yhat^2
drop yhat

// Run RESET tests
qui ppmlhdfe tradeShare_expend z2 cli_imp_greater pta wto_both comcur if tradeShare_expend < 1, absorb(importer_ccode#year exporter_ccode#year importer_ccode#exporter_ccode) clus(importer_ccode#exporter_ccode) nolog d
test z2 = 0

qui ppmlhdfe tradeShare_expend z3 cli_imp_greater pta pta_comp wto_both comcur if tradeShare_expend < 1, absorb(importer_ccode#year exporter_ccode#year importer_ccode#exporter_ccode) clus(importer_ccode#exporter_ccode) nolog d
test z3 = 0

esttab mpml_expend_nocntrl mpml_expend_cntrl mpml_expend_full_cntrl ///
	using "/Users/moda/Dropbox/Apps/Overleaf/ISR - Antitrust/Tables/results_mpml.tex", /// 
	s(years fe_ddyad fe_impyear fe_expyear N, ///
	label("Coverage" "Directed-dyad FE?" "Importer-year FE?" "Exporter-year FE?"  "Observations")) label /// 
	star(* .1 ** .05 *** .01) b(3) se(3) booktabs compress ///
	nomtitles nogap replace
	
	

/************/
/* APPENDIX */
/************/

/* GRAVITY */

// OLS

reghdfe ln_imports cli_imp_greater, absorb(importer_ccode#year exporter_ccode#year importer_ccode#exporter_ccode) clus(importer_ccode#exporter_ccode)
est store ols_bi_nocntrl
estadd local fe_ddyad "Yes"
estadd local fe_impyear "Yes"
estadd local fe_expyear "Yes"
estadd local years "1900-2010"

reghdfe ln_imports cli_imp_greater if year >= 1948, absorb(importer_ccode#year exporter_ccode#year importer_ccode#exporter_ccode) clus(importer_ccode#exporter_ccode)
est store ols_bi_nocntrl_48
estadd local fe_ddyad "Yes"
estadd local fe_impyear "Yes"
estadd local fe_expyear "Yes"
estadd local years "1948-2010"

reghdfe ln_imports cli_imp_greater pta wto_both comcur if year >= 1948, absorb(importer_ccode#year exporter_ccode#year importer_ccode#exporter_ccode) clus(importer_ccode#exporter_ccode) res
est store ols_bi_cntrl_48_nocomp
estadd local fe_ddyad "Yes"
estadd local fe_impyear "Yes"
estadd local fe_expyear "Yes"
estadd local years "1948-2010"

// RESET test
predict yhat, xb
gen z_ols_1 = yhat^2
drop yhat

reghdfe ln_imports cli_imp_greater pta pta_comp wto_both comcur if year >= 1948, absorb(importer_ccode#year exporter_ccode#year importer_ccode#exporter_ccode) clus(importer_ccode#exporter_ccode) res
est store ols_bi_cntrl_48
estadd local fe_ddyad "Yes"
estadd local fe_impyear "Yes"
estadd local fe_expyear "Yes"
estadd local years "1948-2010"

// RESET test
predict yhat, xb
gen z_ols_2 = yhat^2
drop yhat

// PPML

ppmlhdfe imports cli_imp_greater, absorb(importer_ccode#year exporter_ccode#year importer_ccode#exporter_ccode) clus(importer_ccode#exporter_ccode) nolog d
est store ppml_bi_nocntrl_full
estadd local fe_ddyad "Yes"
estadd local fe_impyear "Yes"
estadd local fe_expyear "Yes"
estadd local years "1900-2010"

ppmlhdfe imports cli_imp_greater if year >= 1948, absorb(importer_ccode#year exporter_ccode#year importer_ccode#exporter_ccode) clus(importer_ccode#exporter_ccode) nolog d
est store ppml_bi_nocntrl_48
estadd local fe_ddyad "Yes"
estadd local fe_impyear "Yes"
estadd local fe_expyear "Yes"
estadd local years "1948-2010"

ppmlhdfe imports cli_imp_greater pta wto_both comcur if year >= 1948, absorb(importer_ccode#year exporter_ccode#year importer_ccode#exporter_ccode) clus(importer_ccode#exporter_ccode) nolog d
est store ppml_bi_cntrlnocomp_48
estadd local fe_ddyad "Yes"
estadd local fe_impyear "Yes"
estadd local fe_expyear "Yes"
estadd local years "1948-2010"

// RESET test
predict yhat, xb
gen z_ppml_1 = yhat^2
drop yhat

ppmlhdfe imports cli_imp_greater pta pta_comp wto_both comcur if year >= 1948, absorb(importer_ccode#year exporter_ccode#year importer_ccode#exporter_ccode) clus(importer_ccode#exporter_ccode) nolog d
est store ppml_bi_cntrl_48
estadd local fe_ddyad "Yes"
estadd local fe_impyear "Yes"
estadd local fe_expyear "Yes"
estadd local years "1948-2010"

// RESET test
predict yhat, xb
gen z_ppml_2 = yhat^2
drop yhat

// RESET TESTS

qui reghdfe ln_imports z_ols_1 cli_imp_greater pta wto_both comcur if year >= 1948, absorb(importer_ccode#year exporter_ccode#year importer_ccode#exporter_ccode) clus(importer_ccode#exporter_ccode) res
test z_ols_1 = 0

qui reghdfe ln_imports z_ols_2 cli_imp_greater pta pta_comp wto_both comcur if year >= 1948, absorb(importer_ccode#year exporter_ccode#year importer_ccode#exporter_ccode) clus(importer_ccode#exporter_ccode) res
test z_ols_2 = 0

qui ppmlhdfe imports z_ppml_1 cli_imp_greater pta wto_both comcur if year >= 1948, absorb(importer_ccode#year exporter_ccode#year importer_ccode#exporter_ccode) clus(importer_ccode#exporter_ccode) nolog d
test z_ppml_1 = 0

qui ppmlhdfe imports z_ppml_2 cli_imp_greater pta pta_comp wto_both comcur if year >= 1948, absorb(importer_ccode#year exporter_ccode#year importer_ccode#exporter_ccode) clus(importer_ccode#exporter_ccode) nolog d
test z_ppml_2 = 0


// TABLE OUTPUT

esttab ols_bi_nocntrl ols_bi_nocntrl_48 ols_bi_cntrl_48_nocomp ols_bi_cntrl_48 ppml_bi_nocntrl_full ppml_bi_nocntrl_48 ppml_bi_cntrlnocomp_48 ppml_bi_cntrl_48 ///
	using "/Users/moda/Dropbox/Apps/Overleaf/ISR - Antitrust/Tables/results_gravity_appendix.tex", /// 
	s(years years fe_ddyad fe_impyear fe_expyear N r2, ///
	label("Coverage" "RESET Test" "Directed-dyad FE?" "Importer-year FE?" "Exporter-year FE?"  "Observations" "R$^2$")) label /// 
	star(* .1 ** .05 *** .01) b(3) se(3) booktabs compress ///
	nomtitles nogap replace
